package org.example;

import java.sql.*;
/**
 * Hello world!
 *
 */
public class App 
{
    static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost:3306/cba?serverTimezone=GMT%2B8";

    static final String USER = "root";
    static final String PASS = "cdv123";

    public static void main( String[] args )
    {

        Connection conn = null;
        Statement stmt = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");

            System.out.println("Connecting to database...");
            conn = DriverManager.getConnection(DB_URL, USER, PASS);

            System.out.println("Creating statement...");
            stmt = conn.createStatement();
            String sql;
            sql = "SELECT id, certificate_no, `name`, id_no FROM cdv_certificate_log";
            ResultSet resultSet = stmt.executeQuery(sql);

            while(resultSet.next()){
                int id = resultSet.getInt("id");
                String c_no = resultSet.getString("certificate_no");
                String name = resultSet.getString("name");
                String id_no = resultSet.getString("id_no");

                System.out.print("id: "+id);
                System.out.print("certificate_no: "+c_no);
                System.out.print("name: "+name);
                System.out.print("id_no: "+id_no);
            }

            resultSet.close();
            stmt.close();
            conn.close();


        } catch (Exception ex) {
            System.out.print(ex.toString());
        } finally {

        }
    }
}
